<template>
  <view class="page">
    <!-- #ifdef APP-PLUS -->
    <!-- #endif -->
    <!-- <my-navbar :background="'#12A38C'" leftText="首页" leftIcon="false" @rightClick="toSetting"></my-navbar> -->
    <view class="status_bar"></view>
    <!-- <view class="logos">
      <view class="status_lo">
        <image src="/static/images/weizi.png" />
        <view class="status_loo">
          <span>万达中心b2写字楼</span>
          <image src="../../static/images/xiangxia1.svg" />
        </view>
      </view>
      <view class="status_lo1">
        <image src="/static/images/saoma.png" />
        <image src="/static/images/xiaoxi.png" />
      </view>
    </view> -->

    <my-search :bgColor="'#F8F9FA'" from="business"></my-search>
    <div class="bg_img"></div>
    <view class="content">
      <view class="banner">
        <swiper class="swiper" circular :autoplay="true">
          <swiper-item
            class="swiper_item"
            v-for="(item, index) in banner"
            :key="index"
            @click="detailPage(item.goods_id)"
          >
            <image class="img" :src="item.img" mode="scaleToFill"></image>
          </swiper-item>
        </swiper>
      </view>
      <view class="info flex-middle">
        <image
          class="icon"
          :src="imgSrc"
          style="width: 26rpx; height: 22rpx"
        ></image>
        <!-- #ifndef MP-WEIXIN -->
        <u-notice-bar
          mode="horizontal"
          :speed="100"
          :isCircular="true"
          :list="publicMsg"
          :volume-icon="false"
          bg-color="#F8F9FA"
          color="#333333"
          padding="0"
          style="flex: 1"
        ></u-notice-bar>
        <!-- #endif -->
        <!-- #ifdef MP-WEIXIN -->
        <u-notice-bar 
          mode="horizontal"
          :speed="100"
          :isCircular="true"
          :list="publicMsg"
          :volume-icon="false"
          bg-color="#F8F9FA"
          color="#333333"
          padding="0"
          style="width: 100%; overflow: hidden"
        ></u-notice-bar>
        <!-- #endif -->
      </view>
      <view class="part_box">
        <!--  -->
        <view
          class="part"
          v-for="(item, index) in partData"
          :key="index"
          @click="navigate(item)"
        >
          <image
            class="part_img"
            :src="'/static/home_menu_image/' + item.img + '.png'"
            mode=""
          ></image>
          <text class="part_text">{{ item.name }}</text>
        </view>
      </view>

      <div class="shop">
        <div v-if="supplyList.length != 0">
          <div v-for="(item, index) in supplyList" :key="index">
            <div class="shop-box" @click="navTo(item)">
              <!-- 商品主图 -->
              <div class="shop-box-img">
                <image
                  :src="
                    'https://copartner.oss-cn-beijing.aliyuncs.com/' +
                      item.site_logo ||
                    '../../static/image/logo.jpg'
                  "
                >
                </image>
              </div>
              <!-- 商品信息 -->
              <div class="shop-box-info">
                <span class="title one_ellipsis">{{
                  item.company_name
                }}</span>
                <div class="collect" v-if="item.favorite == 1">
                  <image
                    src="../../static/images/yishoucang.png"
                    alt=""
                    style="
                      width: 84rpx;
                      height: 73rpx;
                      border-top-right-radius: 10rpx;
                    "
                  />
                </div>
                <div class="tip">
                  <span class="tip-content one_ellipsis">{{
                    item.categorys || "暂无"
                  }}</span>
                  <span class="tip-sold"
                    >已售 {{ item.order_count || "0" }}</span
                  >
                </div>
                <div class="seg"></div>
                <div class="condition">
                  <div class="title time">
                    <span> 配送时间</span>
                    <span class="times"
                      >{{ item.open_time | timeFilter }} -
                      {{ item.end_time | timeFilter }}</span
                    >
                  </div>
                  <div class="title money">
                    <span class="moneys"
                      >￥{{ item.starting_price || "0" }}</span
                    >起送
                  </div>
                </div>
                <div class="address">
                  <span class="address-info one_ellipsis"
                    >地址：{{
                      item.address || "暂无"
                    }}</span
                  >
                  <div
                    class="iphone"
                    @click.stop="call(item.site_phone)"
                  >
                    <image src="/static/images/iphone.png"></image>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="noshop" v-else></div>
      </div>
    </view>
    <view class="swite"></view>
    <my-tabar ref="tabar" current="0"></my-tabar>
  </view>
</template>

<script>
import { mixins } from "@/mixins/judgment.js";
// import { mapState } from 'vuex'
import { $https } from "@/static/js/request.js";
// #ifdef H5
const wx = require("jweixin-module");
// #endif
// #ifdef MP-WEIXIN
let plugin = requirePlugin("WechatSI");
// #endif
export default {
  mixins: [mixins],
  data() {
    return {
      total: 0,
      banner: [
        {
          img: "../../static/image/carousel-one.png",
        },
      ],
      imgSrc: "../../static/images/tongz.png",
      partData: [
        {
          id: 1,
          img: "fruit",
          name: "水果",
        },
        {
          id: 1,
          img: "vegetable",
          name: "蔬菜",
        },
        {
          id: 1,
          img: "cooked",
          name: "熟食",
        },
        {
          id: 1,
          img: "solid",
          name: "粮油干粮",
        },
        {
          id: 1,
          img: "poultry",
          name: "家禽",
        },
        {
          id: 1,
          img: "meat",
          name: "生肉",
        },
        {
          id: 1,
          img: "store",
          name: "百货",
        },
        {
          id: 1,
          img: "seafood",
          name: "海鲜",
        },
        {
          id: 1,
          img: "about",
          name: "关于我们",
        },
        {
          id: 1,
          img: "service",
          name: "联系客服",
        },
      ],
      page: 1,
      num: 10,
      alltotal: null,
      wx_url: "",
      telphone: "",
      corpId: "",
      // 供应链列表
      supplyList: [],
      publicMsg: ["流通千万里,溯源零距离"],
    };
  },
  onLoad() {
    this.getContent();
  },
  onShow() {
    this.page = 1;
    this.getData();
    uni.pageScrollTo({
      scrollTop: 0,
      duration: 10,
    });
  },
  methods: {
    getContent() {
      this.publicMsg = [];
      $https("GETN", "getDocument", { type: 5 }, (res) => {
        if (res.data.errcode == 0) {
          this.publicMsg.push(res.data.data.content);
        } else {
        }
      });
    },
    navTo(row) {
      console.log("row1111", row);
      this.determine(row);
    },
    getData(name) {
      $https("GETN", "getUserInfo", {}, (res) => {
        if (res.data.errcode == 0) {
          this.$refs.tabar.changetag(res.data.data.cart_num);
        } else {
          uni.showToast({
            icon: "none",
            title: res.data.errmsg,
          });
        }
      });
      $https(
        "get",
        "supplier-list",
        {
          category_name: name,
          size: 10,
          page: this.page,
        },
        (res) => {
          if (res.data.errcode == 0) {
            if (this.page == 1) {
              this.supplyList = [];
            }
            this.supplyList = this.supplyList.concat(res.data.data.list);
            this.$store.commit("changeCompanyData", res.data.data.list);
            this.total = res.data.data.total;
          } else {
            uni.showToast({
              icon: "none",
              title: res.data.errmsg,
            });
          }
        }
      );
    },

    detailPage(id) {
      console.log(id);
      //没有配置跳转的商品，id为0
      if (id) {
        uni.navigateTo({
          url: `../../pages/index/shopdetail?id=${id}`,
        });
      }
    },
    //跳转
    navigate(item) {
      this.page = 1;
      // if (item.name == "关于我们" || item.name == "联系客服") return;
      if (item.name == "关于我们") {
        uni.navigateTo({
          url: `/pages/account/treaty?type=1`,
        });
        return;
      } else if (item.name == "联系客服") {
        uni.getStorage({
          key: "phone",
          success: function (res) {
            console.log(res.data);
            window.location.href = `tel:${res.data}`;
          },
        });
      } else {
        this.getData(item.name);
        uni.pageScrollTo({
          scrollTop: 0,
          duration: 10, // 可选，滚动时间，默认300ms
        });
      }
    },
    // 电话
    call(phone) {
      uni.makePhoneCall({
        phoneNumber: phone,
        success: (res) => {},
        fail: (res) => {},
      });
    },
  },
  onReachBottom() {
    //如果请求到底就请求下一列表
    if (this.supplyList.length < this.total) {
      this.page++;
      this.getData();
    }
  },
};
</script>

<style lang="scss" scoped>
/deep/.u-drawer {
  overflow: unset !important;
}

.page {
  position: relative;
  font-size: 24rpx;
  box-sizing: border-box;
  min-height: 100vh;
  background: #f8f9fa;

  .logos {
    width: 100%;
    height: 98rpx;
    background-color: #40ae36;
    display: flex;
    justify-content: space-around;
    align-items: center;
    .status_lo {
      height: 36rpx;
      width: 600rpx;
      display: flex;
      // justify-content: space-evenly;
      align-items: center;
      image {
        margin-left: 30rpx;
        width: 31rpx;
        height: 36rpx;
      }
      .status_loo {
        margin-left: 20rpx;
        span {
          height: 29rpx;
          font-size: 30rpx;
          font-family: PingFang SC;
          font-weight: 500;
          color: #ffffff;
        }
        image {
          margin-left: 5rpx;
          margin-bottom: -10rpx;
        }
      }
    }
    .status_lo1 {
      width: 145rpx;
      height: 36rpx;
      display: flex;
      justify-content: space-evenly;
      image {
        width: 34rpx;
        height: 34rpx;
      }
    }
  }

  .bg_img {
    // top:;
    //#ifdef APP-PLUS
    // top: calc(var(--status-bar-height) + 90rpx);
    //#endif
    // width: 750rpx;
    // height: 200rpx;
    // position: absolute;
    // // background-color: #12a38c;
    // z-index: 0;
  }

  .content {
    //#ifndef MP-WEIXIN
    margin-top: var(--status-bar-height);
    //#endif
  }

  .banner {
    // width: 750rpx;
    height: 275rpx;
    position: relative;
    z-index: 1;
    border-radius: 20rpx;
    overflow: hidden;

    .swiper_item {
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .img {
      width: 100%;
      height: 275rpx;
      border-radius: 20rpx;
      margin: 0 30rpx;
    }
  }

  .info {
    position: relative;
    z-index: 1;
    padding: 0 24rpx;
    top: 20rpx;

    .icon {
      width: 2em;
      height: 2em;
      margin-left: 8rpx;
    }
  }

  .part_box {
    position: relative;
    width: 750rpx;
    padding-top: 170rpx;
    z-index: 0;
    background: #f8f9fa;
    overflow: hidden;
    margin: -150rpx 0 0 0;
    display: grid;
    grid-template-rows: repeat(2, 152rpx);
    grid-template-columns: repeat(5, 1fr);
    justify-items: center;
    border-radius: 20rpx;

    .part {
      float: left;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      background: #f8f9fa;
      width: 110rpx;

      .part_img {
        width: 108rpx;
        height: 108rpx;
        margin-bottom: 10rpx;
      }

      .part_text {
        width: 110rpx;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        text-align: center;
        font-size: 28rpx;
        font-family: PingFang SC;
        font-weight: 500;
        color: #000;
      }
    }
  }

  .title {
    font-size: 28rpx;
    font-weight: 500;
    color: #191919;
    // margin-bottom: 16rpx;
  }
}

/deep/.u-mask-show {
  opacity: 1 !important;
}

.shop {
  width: 100%;
  position: relative;
  // margin-top: 10rpx;

  &-box {
    // width: calc(100%);
    box-sizing: border-box;
    margin: 30rpx 30rpx 30rpx 30rpx;
    background-color: #ffffff;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 10rpx;
    border-radius: 10rpx;

    &-img {
      width: 180rpx;
      height: 180rpx;
      border-radius: 10rpx;
      padding: 20rpx;

      image {
        width: 100%;
        height: 100%;
      }
    }

    &-info {
      // width: calc(100% - 48rpx - 9rpx - 180rpx);
      width: 430rpx;
      display: flex;
      flex-direction: column;
      justify-content: space-evenly;
      // margin-left: 9rpx;
      height: 192rpx;
      position: relative;
      // padding: 20rpx 0;

      .collect {
        position: absolute;
        bottom: 135rpx;
        right: -42rpx;
        width: 84rpx;
        height: 73rpx;
        // background-image: url("../../static/images/yishoucang.png");
      }

      .title {
        width: 100%;
        font-size: 32rpx;
        font-weight: 600;
        font-family: PingFangSC-Medium, PingFang SC;
        color: $color_95;
      }

      .tip {
        width: 100%;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;

        &-content {
          font-size: 26rpx;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: $color_75;
          width: 300rpx;
        }

        &-sold {
          width: 130rpx;
          font-size: 26rpx;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: $color_75;
          white-space: nowrap;
          text-align: right;
        }
      }

      .seg {
        width: 100%;
        height: 1rpx;
        background-color: #e5e5e5;
      }

      .condition {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        .title {
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: $color_75;
          font-size: 22rpx;
          white-space: nowrap;
        }

        .time {
          font-size: 22rpx;
          padding-left: 14rpx;
          background-color: #fff5e7;
          min-width: 210rpx;
          width: 224rpx;
          height: 30rpx;
          line-height: 30rpx;
          position: relative;

          span {
            position: relative;
            top: 0rpx;
          }
        }

        .times {
          color: #F55E32;
          margin-left: 10rpx;
        }

        .money {
          width: 160rpx;
          text-align: right;
        }

        .moneys {
          color: #d75131;
          margin-right: 10rpx;
        }
      }

      .address {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 100%;

        &-info {
          width: 380rpx;
          font-size: 26rpx;
          font-family: PingFang SC;
          font-weight: 400;
          color: $color_75;
        }

        .iphone {
          width: 23rpx;
          height: 23rpx;
          display: flex;
          justify-content: center;
          align-items: center;

          image {
            width: 80%;
            height: 80%;
          }
        }
      }
    }
  }
}
.swite {
  padding: 10rpx 0;
}

.noshop {
  width: 750rpx;
  height: 460rpx;
  background-image: url("../../static/loading/noshops.png");
  background-size: 100% 100%;
  margin-bottom: 100rpx;
  // .img {
  //   width: 100%;
  //   height: 100%;
  // }
}
</style>
